package com.education.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.education.platform.entity.PushSubscribe;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 推送订阅Mapper接口
 *
 * @author education-platform
 * @since 2024-10-07
 */
@Mapper
public interface PushSubscribeMapper extends BaseMapper<PushSubscribe> {

    /**
     * 根据用户ID查询订阅列表
     */
    List<PushSubscribe> selectByUserId(@Param("userId") Long userId);

    /**
     * 根据用户ID和客户端类型查询订阅
     */
    PushSubscribe selectByUserIdAndClientType(@Param("userId") Long userId, 
                                            @Param("clientType") String clientType);

    /**
     * 更新最后活跃时间
     */
    void updateLastActiveTime(@Param("id") Long id, @Param("lastActiveAt") LocalDateTime lastActiveAt);

    /**
     * 批量更新订阅状态
     */
    void batchUpdateStatus(@Param("ids") List<Long> ids, @Param("isActive") Boolean isActive);

    /**
     * 删除过期订阅
     */
    void deleteExpiredSubscribes(@Param("beforeDate") LocalDateTime beforeDate);

    /**
     * 查询活跃订阅
     */
    List<PushSubscribe> selectActiveSubscribes(@Param("userIds") List<Long> userIds);
}
